package com.itheima.service.impl;

import com.itheima.dao.QrtzLocksDao;
import com.itheima.pojo.QrtzLocks;
import com.itheima.service.QrtzLocksService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * (QrtzLocks)表服务实现类
 *
 * @author makejava
 * @since 2022-01-16 15:48:52
 */
@Service("qrtzLocksService")
public class QrtzLocksServiceImpl implements QrtzLocksService {
    @Resource
    private QrtzLocksDao qrtzLocksDao;

    /**
     * 通过ID查询单条数据
     *
     * @param schedName 主键
     * @return 实例对象
     */
    @Override
    public QrtzLocks queryById(String schedName) {
        return this.qrtzLocksDao.queryById(schedName);
    }

    /**
     * 分页查询
     *
     * @param qrtzLocks 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<QrtzLocks> queryByPage(QrtzLocks qrtzLocks, PageRequest pageRequest) {
        long total = this.qrtzLocksDao.count(qrtzLocks);
        return new PageImpl<>(this.qrtzLocksDao.queryAllByLimit(qrtzLocks, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param qrtzLocks 实例对象
     * @return 实例对象
     */
    @Override
    public QrtzLocks insert(QrtzLocks qrtzLocks) {
        this.qrtzLocksDao.insert(qrtzLocks);
        return qrtzLocks;
    }

    /**
     * 修改数据
     *
     * @param qrtzLocks 实例对象
     * @return 实例对象
     */
    @Override
    public QrtzLocks update(QrtzLocks qrtzLocks) {
        this.qrtzLocksDao.update(qrtzLocks);
        return this.queryById(qrtzLocks.getSchedName());
    }

    /**
     * 通过主键删除数据
     *
     * @param schedName 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(String schedName) {
        return this.qrtzLocksDao.deleteById(schedName) > 0;
    }
}
